package com.joshondesign.sdljava.gfx;

import com.joshondesign.sdljava.*;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by IntelliJ IDEA.
 * User: josh
 * Date: 9/6/11
 * Time: 10:04 AM
 * To change this template use File | Settings | File Templates.
 */
public class Layer {
    SDL_Surface surface;
    private List<Node> nodes;
    public int x = 0;
    public int y = 0;
    private boolean buffered;

    public Layer(SDL_PixelFormat format) {
        /*
        this._surface = SDL.SDL_CreateRGBSurface(
                SDLConstants.SDL_HWSURFACE|SDLConstants.SDL_SRCALPHA
                ,800,600,
                32, //bbp
                format.getRmask(),
                format.getGmask(),
                format.getBmask(),
                255); //force alpha to be on
        Util.dump(_surface);*/
        this.nodes = new ArrayList<Node>();
    }

    public Layer add(Node rect) {
        this.nodes.add(rect);
        return this;
    }

    public void draw(GFX surface) {
        //clearScreen(_surface);
        /*
        if(isBuffered()) {
            long transparent = SDL.SDL_MapRGBA(_surface.getFormat(),(short)0,(short)0,(short)0,(short)0);
            SDL.SDL_FillRect(this._surface, Util.rect(0,0, _surface.getW(), _surface.getH()),transparent);
        }
        */
        surface.translate(this.x,this.y);
        for(Node node : nodes) {
            node.draw(surface);
        }
        surface.translate(-this.x,-this.y);
        /*
        if(isBuffered()) {
            SDL.SDL_UpdateRect(_surface, 0, 0, _surface.getW(), _surface.getH());
        }
        */
    }

    public void setBuffered(boolean buffered) {
        this.buffered = buffered;
    }

    public boolean isBuffered() {
        return buffered;
    }

    public void setX(double x) {
        this.x = (int) x;
    }
}
